package zhouzhouyongche.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import zhouzhouyongche.model.Day;

@Repository
public class DayDao extends HibernateDao<Day>{

	public Day getOrAdd(int day) {
		Day result = null;
		String hql = "from Day as d where d.day = ?";
		Query q = getCurrentSession().createQuery(hql);
		q.setInteger(0, day);
		List dayList = q.list();
		if (dayList.size() == 0) {
			Day dayObj = new Day();
			dayObj.setDay(day);
			this.save(dayObj);
			
			String _hql = "from Day as d where d.day = ?";
			Query _q = getCurrentSession().createQuery(_hql);
			_q.setInteger(0, day);
			result = (Day)q.list().get(0);
		} else {
			result = (Day)dayList.get(0);
		}
		return result;
	}
}
